<?php

namespace XWAM\Addon\PXCallSystem\Controller;

/**
 * 用户登录模块
 *
 * @since 1.0 2014-6-13 by sutroon
 */
class LoginController extends \Think\Controller {

    public function index() {
        sofn_check_website_status();
        $this->display('TTF' == C('USER.USER_KEY') ? 'ttf' : 'index');
    }

    /**
     * 用户登录
     * @since 1.0 <2015-1-6> sutroon Added.
     */
    public function login() {
        $msg = AddonD('Login')->login(I('login_name'), I('password'), 'TTF' == C('USER.USER_KEY') ? null : I('captcha'));
        if (is_array($msg)) {
            session(C('USER.SESSION_ID'), $msg);
            if ('TTF' == C('USER.USER_KEY')) {
                session(C('USER.SESSION_ID') . '_crm', $msg);
            }
            switch ($msg['userType']) {
                case 'ADMIN': // 普通用户转到策略外呼32
                    $url = AddonU('TaskStrategy/index');
                    break;
                case 'SUPERADMIN': // 超级管理员转到服务器状态78
                    $url = AddonU('Status/sip_server_status');
                    break;
                default:
                    $url = AddonU('Index/index');
                    break;
            }
            if ('TTF' == C('USER.USER_KEY')) {
                $url = AddonU('Index/index');
            }
            $url = U('Index/index');
            redirect($url);
        } else {
            $this->error($msg, AddonU('Login/index'), 1);
        }
    }

    public function logout() {
        AddonD('Login')->logoff();
        redirect(U('Index/index'));
    }

}
